#include "OS/OpenGL/GLWin32WindowManager.h"

#include "Graphics/OpenGL/Win32/GLWin32RenderWindow.h"



namespace tyro
{
	namespace OS
	{
		GLWin32WindowManager::GLWin32WindowManager()
		{

		}


		Graphics::IRenderWindow* GLWin32WindowManager::CreateRenderWindow( const char* const title, UINT_32 width, UINT_32 height, bool isFullscreen )
		{
			Graphics::IRenderWindow* window = new Graphics::GLWin32RenderWindow(*this);

			window->Create(title,width,height,isFullscreen);

			return window;
		}

		bool GLWin32WindowManager::setPixelFormat( HDC deviceContext, UINT_32 colourDepth, UINT32 multisample, bool gamma )
		{

			PIXELFORMATDESCRIPTOR pfd;
			memset(&pfd, 0, sizeof(pfd));
			pfd.nSize = sizeof(pfd);
			pfd.nVersion = 1;
			pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
			pfd.iPixelType = PFD_TYPE_RGBA;
			pfd.cColorBits = (colourDepth > 16)? 24 : colourDepth;
			pfd.cAlphaBits = (colourDepth > 16)? 8 : 0;
			pfd.cDepthBits = 16;
			pfd.cStencilBits = 0;

			UINT32 format = ChoosePixelFormat(deviceContext, &pfd);


			return SetPixelFormat(deviceContext, format, &pfd);

		}

	}
}